package com.example.xianji.utils;

import java.util.ArrayList;

import com.example.xianji.XJApplication;
import com.example.xianji.R;
import com.example.xianji.bean.Share;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.modelmsg.WXWebpageObject;

/**
 * QQ，微信，新浪分享工具类
 * @author me
 *
 */
public class SharesUtil {
	
	
	private static ArrayList<Share> share_list = new ArrayList<Share>();
	
	
	/**
	 * 获取分享图标的集合
	 * @return
	 */
	public static ArrayList<Share> getShareList(){
		share_list.clear();
		Share mShare = new Share();
		Share mShare1 = new Share();
		Share mShare2 = new Share();
		Share mShare3 = new Share();
		Share mShare4 = new Share();
		Share mShare5 = new Share();
		Share mShare6 = new Share();
		mShare.setDrawle(R.drawable.download);
		mShare.setName("微信好友");

		mShare1.setDrawle(R.drawable.friend);
		mShare1.setName("微信朋友圈");

		mShare2.setDrawle(R.drawable.weixin_collection);
		mShare2.setName("微信收藏");

		mShare3.setDrawle(R.drawable.tengxun_weibo);
		mShare3.setName("腾讯微博");

		mShare4.setDrawle(R.drawable.xinlang_weibo);
		mShare4.setName("新浪微博");

		mShare5.setDrawle(R.drawable.qie);
		mShare5.setName("QQ");

		mShare6.setDrawle(R.drawable.kongjian);
		mShare6.setName("QQ空间");
		share_list.add(mShare);
		share_list.add(mShare1);
		share_list.add(mShare2);
		share_list.add(mShare3);

		share_list.add(mShare4);
		share_list.add(mShare5);
		share_list.add(mShare6);
		return share_list;
		
	}
	/**
	 * 分享微信好友
	 */
	public static void weiXin_showShare(String share_url,String title) {

		WXWebpageObject webpage = new WXWebpageObject();
		// webpage.webpageUrl = "http://www.baidu.com";
		webpage.webpageUrl = share_url;
		WXMediaMessage msg = new WXMediaMessage(webpage);
		msg.title = title;
		msg.description = share_url;

		SendMessageToWX.Req req1 = new SendMessageToWX.Req();
		req1.transaction = buildTransaction("webpage");
		req1.message = msg;
		req1.scene = SendMessageToWX.Req.WXSceneSession;
		XJApplication.getApi().sendReq(req1);

	}
	private static  String buildTransaction(final String type) {
		return (type == null) ? String.valueOf(System.currentTimeMillis())
				: type + System.currentTimeMillis();
	}
	
	/**
	 * 微信朋友圈分享
	 */
	public static  void weiXin_prnyyouquan_showShare(String share_url ,String title) {

		SendMessageToWX.Req req = new SendMessageToWX.Req();
		req.scene = SendMessageToWX.Req.WXSceneTimeline;

		req.transaction = buildTransaction("webpage");
		req.message = new WXMediaMessage();

		req.message.title = title;

		req.message.mediaObject = new WXWebpageObject(share_url);

		XJApplication.getApi().sendReq(req);

	}
	/**
	 * 微信收藏
	 */
	public static void weiXin_collection_showShare(String share_url ,String title) {

		SendMessageToWX.Req req = new SendMessageToWX.Req();
		req.scene = SendMessageToWX.Req.WXSceneFavorite;

		req.transaction = buildTransaction("webpage");
		req.message = new WXMediaMessage();

		req.message.title = title;

		req.message.mediaObject = new WXWebpageObject(share_url);

		XJApplication.getApi().sendReq(req);

	}
	

}
